#include <stdio.h>
#include <stdlib.h>

#include "LinkList.h"

void visit(ElemType e)
{
    printf("%d\t",e);
}

Boolean compare(ElemType e1,ElemType e2)
{
    return e1 == e2 ? TRUE : FALSE;
}

int main()
{

    LinkList me;
    int ret,i;

    ret = InitList(&me);
    if (ret != OK)
    {
        printf("LinkList init failed!\n");
        exit(-1);
    }
/**
    Boolean isempty;
    isempty = ListEmpty(me);
    printf("linklist is %s\n",isempty ? "empty" : "notempty");
*/

    for ( i = 0; i < 8; i++)
    {
        /**
        if (i == 6)
        {
            ret = ListInsert(me,i,78);
            if (ret != OK)
            {
                printf("List Insert failed!\n");
                break;
            }
            
            continue;
        }
        */
        ret = ListInsert(me,i,rand()%100);
        if (ret != OK)
        {
            printf("List Insert failed!\n");
            break;
        }
    }
    
    ListTraverse(me,visit);

    ret = ListInsert(me,45,12);
    if (ret != OK)
    {
        printf("ret = %d\n",ret);
        printf("List Insert failed!\n");
    }
/**
    ElemType temp;

    ret = NextElem(me,58,&temp);
    if (ret == OK)
    {
        printf("next elem is %d\n",temp);
    }else{
        printf("no next elem\n");
    }
*/    

/**
    ElemType temp;
    
    ret = PriorElem(me,44,&temp);
    if (ret == OK)
    {
        printf("the prior elem is %d\n",temp);
    }else{
        printf("no prior elem\n");
    }
*/    

/**
    ret = LocateElem(me,24,compare);
    printf("the elem index is %d\n",ret);
*/

/**
    ElemType temp;

    ret = GetElem(me,8,&temp);
    if (ret!=OK)
    {
        printf("no this elem!\n");
    }else{
        printf("elem is:");
        visit(temp);
    }
*/

 /**   
    ret = ListDelete(me,8,&temp);
    if (ret != OK)
    {
        printf("delete elem failed!\n");
    }else{
        printf("delete elem is:");
        visit(temp);
    }
*/
/**
    int count;
    count = ListLength(me);
    printf("LinkList has %d elem\n",count);

*/

/**
    LinkList list;

    ret = CreateList_Head(&list,4); 
    if (ret != OK)
    {
        printf("createlist by head insert failed!\n");
    }
    
    ListTraverse(list,visit);

    DestroyList(&list);
 */   


/**
    ret = CreateList_Tail(&list,5);
    if (ret != OK)
    {
        printf("createlist by tail insert failed!\n");
    }
    ListTraverse(list,visit);

    DestroyList(&list);
*/
    DestroyList(&me);
    exit(0);
}